<?php
error_reporting(0);
session_start();
if(!session_id())session_start();
ob_start();
if( isset( $_SESSION['user'] ) ){
}else{
    echo("<script type='text/javascript'>alert('请先登录！');window.location.href='./index.php';</script>");
}
include "../config.php";


$user = $_POST[name];
$pass = $_POST[pass];
$sql="select * from admin where `username`='$user' and `passwd`='$pass'";
$result=$conn->query($sql);
if ($result){
    $row=mysqli_fetch_array($result);
    if($row){
        echo("<script type='text/javascript'>alert('登录成功！');window.location.href='main.php';</script>");
        session_start();
        $_SESSION["user"] =$row['username'];
        exit;
    }
    else{
        echo("<script type='text/javascript'>alert('登录失败！');window.location.href='login.php';</script>");
    }
}

//echo $user,$pass;
//if($user != $name){
//    exit("<script language='javascript'>alert('无此用户，请检查您输入的用户是否正确!');window.location.href='login.php';</script>");
//}else if($pass != $adminpass){
//    exit("<script language='javascript'>alert('您输入的密码错误，请检查您是否输入正确!');window.location.href='login.php';</script>");
//}
//else{
    session_start();
    $_SESSION["user"] = $name;
//    header("Location:main.php");
//}
?>